<?php

namespace App\Http\Controllers\Admin\Collection;

use App\Http\Controllers\Controller;
use App\Models\Common\CollOption;
use Illuminate\Http\Request;
use Style;

//调用phpQuery类
require(app_path('Vendor/phpQuery/phpQuery.php'));


/**
 * tzzp采集类
 * Class FiveEight
 * @package App\Http\Controllers\Admin\Collection
 */
class Tzzp extends Controller{

    //简历板块----------------------------------------------------------------------------------------------------------------
    /**
     * 获取tzzp简历信息
     * @param $listData
     * @return array
     */
    static public function getResumeInfo($listData){
        //使用phpQuery
        if(preg_match_all("/<ul class=\"findone-list clearfix\">(.*)<\/ul>/Uis", $listData, $arr)){
            if(preg_match_all("/<li>\s*<input(.*)value=\"(.*)\"(.*)<a href=(\'|\")(.*)(\'|\")(.*)<\/a>(.*)<\/li>/Uis", $arr[1][0], $arr1)){
                if(count($arr1[5]) > 0){
                    $arrInfo = [];
                    foreach($arr1[5] as $k => $v){
                        $arrInfo[] = array(
                            'resumeId' => $arr1[2][$k],//简历ID(截取前面25个做为用户的唯一ID)
                            'resumeUrl' => trim($v)   //简历列表的跳转地址
                        );
                    }
                    //删除重复项
                    $collection = collect($arrInfo);
                    $arrInfo = $collection->unique('resumeId');
                    return $arrInfo;
                }
            };
        }else{
            //获取tzzp简历信息匹配不存在
            return 'error';
        };
    }

    /**
     * 简历内容
     * @param $resumeId
     * @param $resumeUrl
     * @param $cookie
     * @param $collArea
     * @return array
     */
    static public function resumeCon($resumeId, $resumeUrl, $cookie, $collArea, $upMobile = ''){
        //tzzp岗位数组
        require(app_path('Repositories/Array/tzzp_job.php'));
        require(app_path('Repositories/Array/tzzp_language.php'));
        //$resumeUrl = 'http://www.tzzp.com/resume/bce_1490901_2_.html';
        //由于tzzp需要通过ajax加载获取页面 重新组合url地址
        preg_match("/http:\/\/www.tzzp.com\/resume\/(.*)_(.*)_2_.html/Uis", $resumeUrl, $arr1);
        $encrypt = trim($arr1[1]);
        $Perid = trim($arr1[2]);
        $ajaxResumeUrl = 'http://www.tzzp.com/Resume/Resume2017.aspx?Perid=' . $Perid . '&Encrypt=' . $encrypt . '&r=' . time();
        $con = getCurlCon($ajaxResumeUrl, $cookie);
        //使用phpQuery
        $con = \phpQuery::newDocument($con);
        $error_bd = trim(pq(".error_bd")->find('h1')->html());
        if(!empty($error_bd)){
            //采集信息该页面不存在出错
            return 'err';
        }
        //简历信息内容
        /**************************************************************************************************************************/
        //基本信息
        $avatar = trim(pq(".contentleft .contentbase")->find('#touxiang1')->attr('src'));//头像
        $name = trim(pq(".contentleft .baselist")->find('.resumename')->html());//姓名
        $sex = trim(pq(".contentleft .baselist")->find('.resumeinfo')->find('span:eq(0)')->html());//性别
        $sex = ($sex == '男') ? '1' : '2';
        $birthday = trim(pq(".contentleft .baselist")->find('.resumeinfo')->find('span:eq(1)')->html());//年龄
        $birthday = date('Y-m-d',strtotime('-'.$birthday.' years'));

        preg_match("/<em>最高学历：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .baselist")->html(), $arr2);
        $edu = (!empty($arr2[1])) ? trim($arr2[1]) : '';//学历

        switch($edu){
            case  '初中及以下':
                $edu = '10';
                break;
            case  '高中':
                $edu = '20';
                break;
            case  '中专':
                $edu = '30';
                break;
            case  '大专':
                $edu = '40';
                break;
            case  '本科':
                $edu = '50';
                break;
            case  '硕士':
                $edu = '60';
                break;
            case  '博士':
                $edu = '70';
                break;
            case  '博士后':
                $edu = '70';
                break;
            default:
                $edu = '';
        }

        preg_match("/<em>工作经验：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .baselist")->html(), $arr3);
        $work_year = (!empty($arr3[1])) ? trim($arr3[1]) : '';//工作经验
        switch($work_year){
            case  '应届生':
                $work_year = '10';
                break;
            case  '在读生':
                $work_year = '9';
                break;
            case  '1-3年':
                $work_year = '11';
                break;
            case  '3-5年':
                $work_year = '13';
                break;
            case  '5-10年':
                $work_year = '15';
                break;
            case  '10年以上':
                $work_year = '20';
                break;
            default:
                $work_year = '';
        }
        preg_match("/<em>婚姻状况：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .baselist")->html(), $arr4);
        $marital = (!empty($arr4[1])) ? trim($arr4[1]) : ''; //婚姻状况
        switch($marital){
            case  '未婚':
                $marital = '1';
                break;
            case  '已婚':
                $marital = '2';
                break;
            case  '离异':
                $marital = '3';
                break;
            case  '保密':
                $marital = '4';
                break;
            default:
                $marital = '4';
        }

        //匹配相似度
        preg_match("/<em>现居住地：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .baselist")->html(), $arr5);
        $homeaddress = trim($arr5[1]);//现居住地
        $address = (!empty($homeaddress) && $homeaddress != '保密') ? $homeaddress : '';//地址
        $homeaddress = (!empty($homeaddress) && $homeaddress != '保密') ? Common::signSimilarity($collArea, $homeaddress) : '';
        //匹配相似度
        preg_match("/<em>籍<span class=\"w2\"><\/span>贯：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .baselist")->html(), $arr6);
        $census = (!empty($arr6[1]) && trim($arr6[1]) != '保密') ? Common::signSimilarity($collArea, trim($arr6[1])) : '';
        $height = trim(pq(".contentleft .baselist")->find('#shengao')->html());//身高
        $height = (!empty($height) && $height != '保密') ? $height : '';
        $height = str_replace('CM', '', $height);//月薪


        preg_match("/<div class=\"dynamictip \">\s*<p>\s*求职状态：(.*),可随时电话联系我<\/p>\s*<\/div>/Uis", pq(".contentleft .dynamicbox")->html(), $arr7);
        $job_status = (!empty($arr7[1])) ? trim($arr7[1]) : '';
        switch($job_status){
            case  '在岗':
                $job_status = '3';
                break;
            case  '在职':
                $job_status = '2';
                break;
            case  '离职':
                $job_status = '1';
                break;
            case  '待业':
                $job_status = '1';
                break;
            default:
                $job_status = '1';
        }
        //工作岗位
        preg_match("/<em>期望职位：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .contentlist")->html(), $arr11);
        $expectJob = (!empty(trim($arr11[1]))) ? trim($arr11[1]) : '';//期望职位
        $intentionjobs = (!empty($expectJob)) ? $expectJob : '';//意向岗位
        $job = (!empty($expectJob)) ? explode(',', $expectJob) : [];
        //职位
        $jobsort1 = !empty($job[0]) ? Common::matchJob(trim($job[0]), $jobArray) : '';
        $jobsort2 = !empty($job[1]) ? Common::matchJob(trim($job[1]), $jobArray) : '';
        $jobsort3 = !empty($job[2]) ? Common::matchJob(trim($job[2]), $jobArray) : '';
        $jobsort4 = !empty($job[3]) ? Common::matchJob(trim($job[3]), $jobArray) : '';
        $jobsort5 = !empty($job[4]) ? Common::matchJob(trim($job[4]), $jobArray) : '';
        //工作地区
        preg_match("/<em>期望地点：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .contentlist")->html(), $arr12);
        $locationCon = (!empty($arr12[1])) ? trim($arr12[1]) : '';//期望工作地区
        $locationCon = (!empty($locationCon) && $locationCon == '不限') ? '台州市' : $locationCon;
        $location = (!empty($locationCon)) ? explode(' ', $locationCon) : [];
        //匹配相似度
        $jobArr = Common::similarity($collArea, $location);
        $jobarea1 = !empty($jobArr[0]) ? trim($jobArr[0]) : '';
        $jobarea2 = !empty($jobArr[1]) ? trim($jobArr[1]) : '';
        $jobarea3 = !empty($jobArr[2]) ? trim($jobArr[2]) : '';
        $jobarea4 = !empty($jobArr[3]) ? trim($jobArr[3]) : '';
        $jobarea5 = !empty($jobArr[4]) ? trim($jobArr[4]) : '';

        //期望薪资
        preg_match("/<em>期望月薪：<\/em><span>(.*)<\/span>/Uis", pq(".contentleft .contentlist")->html(), $arr13);
        $money = (!empty(trim($arr13[1]))) ? trim($arr13[1]) : '';//期望职位
        if(strstr($money, '￥')){
            $money = str_replace('￥', '', $money);//月薪
            $moneyArr = explode('~', $money);
            $expectedsalary = (!empty($moneyArr[0]) && $moneyArr[0] != '0' && $moneyArr[0] != '面议') ? $moneyArr[0] : '面议';
            if(substr($expectedsalary, -1, 1) == '1' && $expectedsalary != '面议'){
                $expectedsalary = (int)$expectedsalary - 1;
            }
            $isexpectedsalary = 0;
        }else{
            $expectedsalary = '面议';
            $isexpectedsalary = 1;
        }
        $mobile = '';
        $email = '';
        $qq = '';
        //招聘网手机站获取电话号码和邮箱
        if($upMobile != '1'){ //为1代表已经存在临时简历库。对这份简历不更新联系方式（手机号码、邮箱、qq、出生日期）
            //新版本获取手机号码
            $downresumeurl = 'http://m.tzzp.com/companycenter/previewresume.aspx?cmd=persondownload&Perid=' . $Perid . '&dt=' . time();
            $downresumecon = getCurlCon($downresumeurl, $cookie);
            $statusArr = json_decode($downresumecon, true);
            if($statusArr['status'] == 'success'){
                $mobile = trim($statusArr['mobile']);
                $email = trim($statusArr['mail']);
                $qq = trim($statusArr['msnqq']);
            }
            //老版本使用的获取tzzp手机号码
//            $downresumeurl = 'http://m.tzzp.com/ControlsCom/CompanyHandler.ashx?action=downresume&perid=' . $Perid . '&r=' . time();
//            $downresumecon = getCurlCon($downresumeurl, $cookie);
//            $statusArr = json_decode($downresumecon, true);
//            if($statusArr['status'] == '1'){
//                //手机站地址获取电话号码
//                $mresumeurl = 'http://m.tzzp.com/Resume/' . $encrypt . '_' . $Perid . '.html';
//                $mcon = getCurlCon($mresumeurl, $cookie);
//                if(preg_match("/<li><em class='title'>手机号码<\/em><span class='data'>(.*)<\/span><\/li>/Uis", $mcon, $arr30)){
//                    $mobile = trim($arr30[1]);
//                }
//                if(preg_match("/<li><em class='title'>电子邮箱<\/em><span class='data'>(.*)<\/span><\/li>/Uis", $mcon, $arr31)){
//                    $email = trim($arr31[1]);
//                }
//                if(preg_match("/<li><em class='title'>QQ号码<\/em><span class='data'>(.*)<\/span><\/li>/Uis", $mcon, $arr32)){
//                    $qq = trim($arr32[1]);
//                }
//                if(preg_match("/<li>\s*<em class=\"title\">出生日期<\/em><span class=\"data\">(.*)<\/span><\/li>/Uis", $mcon, $arr33)){
//                    $birthday = trim($arr33[1]);
//                }
//            }
        }

        //dd($birthday);
        /**************************************************************************************************************************/
        //自我评价
        preg_match("/自我评价<\/h2>\s*<div(.*)>(.*)<\/div>/Uis", pq(".contentleft")->html(), $arr14);
        $introduction = (!empty($arr14[2])) ? trim($arr14[2]) : '';
        $introduction = preg_replace('/(<br>|<br \/>)/Uis', "\r\n", $introduction);
        $basicArr = [];
        $basicArr = array(
            //  'avatar' => $avatar,
            'name' => $name,
            'sex' => $sex,
            'birthday' => $birthday,
            'education' => $edu,
            'work_year' => $work_year,
            'expectedsalary' => $expectedsalary,
            'isexpectedsalary' => $isexpectedsalary,
            'census' => $census,
            'homeaddress' => $homeaddress,
            'address' => $address,
            'jobsort1' => $jobsort1,
            'jobsort2' => $jobsort2,
            'jobsort3' => $jobsort3,
            'jobsort4' => $jobsort4,
            'jobsort5' => $jobsort5,
            'jobarea1' => $jobarea1,
            'jobarea2' => $jobarea2,
            'jobarea3' => $jobarea3,
            'jobarea4' => $jobarea4,
            'jobarea5' => $jobarea5,
            'mobile' => $mobile,
            'email' => $email,
            'qq' => $qq,
            'job_status' => $job_status,
            'introduction' => $introduction,
            'intentionjobs' => $intentionjobs,
            'show_type' => 1,
            'marital' => $marital,
            'height' => $height,
            'regtime' => date('Y-m-d H:i:s', time()),
            'updatetime' => date('Y-m-d H:i:s', time())
        );
        //dd($basicArr);

        /**************************************************************************************************************************/
        //工作经验
        $workArr = [];
        if(preg_match("/工作经历<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr20)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr20[1], $arr21)){
                if(count($arr21[1]) > 0){
                    foreach($arr21[1] as $v){
                        preg_match("/<em(.*)>(.*)时 间：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr22);
                        $worktime = trim($arr22[4]);//工作时间
                        $starttime = '';
                        $endtime = '';
                        if(strstr($worktime, '-')){
                            list($starttime, $endtime) = explode('-', $worktime);
                            $starttime = trim(preg_replace('/(年|月)/', '-', $starttime)) . '00';
                            $endtime = ($endtime == '目前' || $endtime == '至今') ? '0000-00-00' : trim(preg_replace('/(年|月)/', '-', $endtime)) . '00';
                        }
                        preg_match("/<em class=\"leftem\">公司名称：<\/em>\s*<span>(.*)<\/span>/Uis", $v, $arr23);
                        $company = trim($arr23[1]);//公司名称
                        preg_match("/<em class=\"leftem\">担任职位：<\/em>\s*<span>(.*)<\/span>/Uis", $v, $arr24);
                        $post = trim($arr24[1]);//在职职位
                        preg_match("/<em class=\"leftem\">描<span(.*)><\/span>述：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr25);
                        $content = trim($arr25[3]);//工作描述
                        $content = preg_replace('/(<br>|<br \/>)/Uis', "\r\n", $content);
                        $workArr[] = array(
                            'company' => $company,
                            'starttime' => $starttime,
                            'endtime' => $endtime,
                            'post' => $post,
                            'content' => $content,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }
//        dd($workArr);
        /**************************************************************************************************************************/
        //教育经历
        $educationArr = [];
        if(preg_match("/教育培训<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr20)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr20[1], $arr21)){
                if(count($arr21[1]) > 0){
                    foreach($arr21[1] as $v){
                        preg_match("/<em(.*)>(.*)时 间：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr22);
                        $edutime = trim($arr22[4]);//教育时间
                        $starttime = '';
                        $endtime = '';
                        if(strstr($edutime, '-')){
                            list($starttime, $endtime) = explode('-', $edutime);
                            $starttime = trim(preg_replace('/(年|月)/', '-', $starttime)) . '00';
                            $endtime = ($endtime == '目前' || $endtime == '至今') ? '0000-00-00' : trim(preg_replace('/(年|月)/', '-', $endtime)) . '00';
                        }
                        preg_match("/<em class=\"leftem\">学<span(.*)><\/span>校：<\/em><span>(.*)<\/span>/Uis", $v, $arr23);
                        $school = trim($arr23[2]);//学校名称
                        preg_match("/<em class=\"leftem\">学<span(.*)><\/span>历：<\/em><span>(.*)<\/span>/Uis", $v, $arr26);
                        $education = trim($arr26[2]);//学历
                        switch($education){
                            case  '初中及以下':
                                $education = '10';
                                break;
                            case  '高中':
                                $education = '20';
                                break;
                            case  '中专':
                                $education = '30';
                                break;
                            case  '大专':
                                $education = '40';
                                break;
                            case  '本科':
                                $education = '50';
                                break;
                            case  '硕士':
                                $education = '60';
                                break;
                            case  '博士':
                                $education = '70';
                                break;
                            case  '博士后':
                                $education = '70';
                                break;
                            default:
                                $education = '';
                        }
                        preg_match("/<em class=\"leftem\">专业课程：<\/em>\s*<span>(.*)<\/span>/Uis", $v, $arr24);
                        $speciality = trim($arr24[1]);//专业课程名称
                        preg_match("/<em class=\"leftem\">专业描述：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr25);
                        $description = !empty($arr25[2]) ? trim($arr25[2]) : '';//教育描述
                        $description = preg_replace('/(<br>|<br \/>)/Uis', "\r\n", $description);
                        $educationArr[] = array(
                            'school' => $school,
                            'edu_type' => 1,
                            'starttime' => $starttime,
                            'endtime' => $endtime,
                            'speciality' => $speciality,
                            'education' => $education,
                            'description' => $description,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }

        //项目经验
        $projectArr = [];
        if(preg_match("/项目经验<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr30)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr30[1], $arr31)){
                if(count($arr31[1]) > 0){
                    foreach($arr31[1] as $v){
                        preg_match("/<em(.*)>(.*)时 间：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr32);
                        $edutime = trim($arr32[4]);//教育时间
                        $starttime = '';
                        $endtime = '';
                        if(strstr($edutime, '-')){
                            list($starttime, $endtime) = explode('-', $edutime);
                            $starttime = trim(preg_replace('/(年|月)/', '-', $starttime)) . '00';
                            $endtime = ($endtime == '目前' || $endtime == '至今') ? '0000-00-00' : trim(preg_replace('/(年|月)/', '-', $endtime)) . '00';
                        }
                        preg_match("/<em class=\"leftem\">项目名称：<\/em><span>(.*)<\/span>/Uis", $v, $arr33);
                        $project_name = trim($arr33[1]);//项目名称
                        preg_match("/<em class=\"leftem\">项目描述：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr34);
                        $content = !empty($arr34[2]) ? trim($arr34[2]) : '';//项目描述
                        $content = preg_replace('/(<br>|<br \/>)/Uis', "\r\n", $content);
                        $projectArr[] = array(
                            'project_name' => $project_name,
                            'starttime' => $starttime,
                            'endtime' => $endtime,
                            'content' => $content,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }
        //语言能力
        $languageArr = [];
        if(preg_match("/语言能力<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr30)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr30[1], $arr31)){
                if(count($arr31[1]) > 0){
                    foreach($arr31[1] as $v){
                        preg_match("/<em(.*)>(.*)语言类别：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr32);
                        $language = trim($arr32[4]);//教育时间
                        $language = (!empty($language)) ? Common::matchJob($language, $languageArray) : '';
                        preg_match("/<em(.*)>(.*)掌握程度：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr33);
                        $degree = trim($arr33[4]);//教育时间
                        switch($degree){
                            case  '一般':
                                $degree = '1';
                                break;
                            case  '良好':
                                $degree = '1';
                                break;
                            case  '熟练':
                                $degree = '2';
                                break;
                            case  '精通':
                                $degree = '3';
                                break;
                            default:
                                $degree = '4';
                        }
                        $languageArr[] = array(
                            'language' => $language,
                            'degree' => $degree,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }
        //技能专长
        $skillArr = [];

        //获得证书
        $certificateArr = [];
        if(preg_match("/获得证书<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr30)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr30[1], $arr31)){
                if(count($arr31[1]) > 0){
                    foreach($arr31[1] as $v){
                        preg_match("/<em(.*)>(.*)获得时间：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr32);
                        $gettime = trim($arr32[4]);//教育时间
                        $gettime = ($gettime == '目前' || $gettime == '至今') ? '0000-00-00' : trim(preg_replace('/(年|月)/', '-', $gettime)) . '00';
                        preg_match("/<em class=\"leftem\">证书名称：<\/em><span>(.*)<\/span>/Uis", $v, $arr33);
                        $certificate_name = trim($arr33[1]);//证书名称
                        $certificateArr[] = array(
                            'certificate_name' => $certificate_name,
                            'gettime' => $gettime,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }
        //其它信息
        $otherArr = [];
        if(preg_match("/附加信息<\/h2>\s*<table class=\"contentlist\">(.*)<\/table>/Uis", pq(".contentleft")->html(), $arr30)){
            if(preg_match_all("/<tbody>(.*)<\/tbody>/Uis", $arr30[1], $arr31)){
                if(count($arr31[1]) > 0){
                    foreach($arr31[1] as $v){
                        preg_match("/<em(.*)>标(.*)题：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr32);
                        $title = trim($arr32[4]);//教育时间
                        preg_match("/<em(.*)>描(.*)述：<\/em>\s*<span(.*)>(.*)<\/span>/Uis", $v, $arr34);
                        $content = !empty($arr34[2]) ? trim($arr34[4]) : '';//项目描述
                        $content = preg_replace('/(<br>|<br \/>)/Uis', "\r\n", $content);
                        $otherArr[] = array(
                            'title' => $title,
                            'content' => $content,
                            'addtime' => date('Y-m-d H:i:s', time()),
                            'updatetime' => date('Y-m-d H:i:s', time())
                        );
                    }
                }
            }
        }
        //简历内容
        $arrayCon = array(
            'resumeId' => $resumeId,
            'resumeUrl' => $resumeUrl,
            'basic' => $basicArr,
            'work' => $workArr,
            'project' => $projectArr,
            'education' => $educationArr,
            'language' => $languageArr,
            'skill' => $skillArr,
            'certificate' => $certificateArr,
            'other' => $otherArr
        );
//        dd($arrayCon);
        return $arrayCon;
    }


    //企业板块----------------------------------------------------------------------------------------------------------------
    /**
     * 获取tzzp企业信息
     * @param $listData
     * @return array|static
     */
    static public function getCompanyInfo($listData){
        //使用phpQuery
        if(preg_match_all("/<ul class=\"findwork-list\">(.*)<ul class=\"findwork-table\"/Uis", $listData, $arr)){
            if(preg_match_all("/<ul class=\"company\">\s*<li><a href=(\'|\")(.*)(\'|\")(.*)<\/a>(.*)<\/li>\s*<\/ul>/Uis", $arr[1][0], $arr1)){
                if(count($arr1[2]) > 0){
                    $arrInfo = [];
                    foreach($arr1[2] as $v){
                        if(preg_match("/\/company\/(.*)(\d+)\.html/Uis", $v, $arr2)){
                            $arrInfo[] = array(
                                'companyId' => trim($arr2[2]),//企业ID用户的唯一ID
                                'companyUrl' => trim($v)  //企业列表的跳转地址
                            );
                        }
                    }
                    //删除重复项
                    $collection = collect($arrInfo);
                    $arrInfo = $collection->unique('companyId');
                    return $arrInfo;
                }
            }
        }else{
            //获取tzzp简历信息匹配不存在
            return 'error';
        }
    }

    /**
     * 企业内容
     * @param $companyId
     * @param $companyUrl
     * @param $cookie
     * @return string
     */
    static public function companyCon($companyId, $companyUrl, $cookie){
        //$companyUrl = 'http://www.tzzp.com/company/aee182303.html';
        $con = getCurlCon($companyUrl, $cookie);
        //使用phpQuery
        $con = \phpQuery::newDocument($con);
        $error_bd = trim(pq(".error_bd")->find('h1')->html());
        if(!empty($error_bd)){
            //采集信息该页面不存在出错
            return 'err';
        }
        //企业信息内容
        $companyName = trim(pq(".main-top .msg")->find('h1')->html());//公司名称
        $address = trim(pq(".main-content .address")->find('.addmsg p')->html());//公司名称
        //部门职位列表
        $jobArr = [];
        $jobList = pq(".main-content .joblist")->find('.item-section');//所有部门的职位
        if(!empty($jobList)){
            foreach($jobList as $v){
                $job_info = pq($v)->find('.item-can');//部门下面的职位
                foreach($job_info as $vv){
                    $job_title = trim(pq($vv)->find('.job-base')->find("h4 a")->html());//职位名称
                    $jobArr[] = $job_title;
                }
            }
        }
        $jobArr = array_unique($jobArr);//合并相同的职位名称
        $remarks = implode('，', $jobArr);//链接职位名称
        //随机一个职位地址
        $job_rand_url = trim(pq(".main-content .joblist")->find('.item-section')->find('.item-can:eq(0)')->find("h4 a")->attr('href'));
        //职位列表信息
        $jobCon = getCurlCon($job_rand_url, $cookie);
        //使用phpQuery
        $jobCon = \phpQuery::newDocument($jobCon);
        $phone1 = trim(pq(".main .jobdtl-data")->find('.jobdtlcan')->find('.teldtl')->nextAll('span:eq(0)')->html());//电话1
        $phone2 = trim(pq(".main .jobdtl-data")->find('.jobdtlcan')->find('.teldtl')->nextAll('span:eq(1)')->html());//电话2
        $mobile = '';
        $phone = '';
        if(!empty($phone1) && strlen($phone1) == '11'){
            $mobile = $phone1;
        }else{
            $phone = $phone1;
        }
        if(!empty($phone2) && strlen($phone2) == '11'){
            $mobile .= ',' . $phone2;
        }else{
            $phone .= ',' . $phone2;
        }
        $mobile = trim($mobile, ',');
        $phone = trim($phone, ',');
        $contacts = trim(pq(".main .jobdtl-data")->find('.jobdtlcan')->find('.teldtl')->nextAll('b')->html());//公司名称
        $contacts = preg_replace('/(\(|\))/Uis', "", $contacts);
        $email = trim(pq(".main .jobdtl-data")->find('.jobdtlcan')->find('.maildtl')->nextAll('span')->html());//邮箱
        $web = trim(pq(".main .main-content")->find('.basemsg')->find('dl')->find('dd:eq(0)')->find('a')->attr('href'));//公司主页

        //企业基本信息
        $basicArr = array(
            'name' => $companyName,
            'address' => $address,
            'web' => $web,
            'contacts' => $contacts,
            'phone' => $phone,
            'mobile' => $mobile,
            'email' => $email,
            'remarks' => $remarks,
            'created_at' => date('Y-m-d H:i:s', time()),
            'updated_at' => date('Y-m-d H:i:s', time()),
            'visit_time' => date('Y-m-d H:i:s', time())
        );
        //简历内容
        $arrayCon = array(
            'companyId' => $companyId,
            'companyUrl' => $companyUrl,
            'companyArr' => $basicArr,
        );
        return $arrayCon;
    }
}
